﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style>

    .layui-table-tool > .layui-table-tool-temp {
        padding-right: 0px;
    }
</style>
<script>
    layui.use(['jquery', 'form', 'table', 'common', 'commonTable', 'optimizeSelectOption'], function () {
        var $ = layui.jquery,
            form = layui.form,
            commonTable = layui.commonTable,
            table = layui.table,
            common = layui.common;
        var keyValue = $.request("keyValue");
        //权限控制(js是值传递)
        toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
        $(function () {
            initControl();
            common.ajax({
                url: '/MaterialManage/Material/GetFormJson',
                dataType: 'json',
                data: { keyValue: keyValue },
                async: false,
                success: function (data) {
                    common.val('adminform', data);
                    common.setReadOnly('adminform');
                    MaterialTypeChange(data.F_MaterialType);
                    $('button[lay-filter="data-search-btn"]').click();//按钮刷新
                }
            });
            form.render();
        });
        function initControl() {
            $("#F_MaterialType").bindSelect({
                data: top.clients.dataItems['Mes_MaterialType'],
                id: "",
            });
        }
        //监听复选框
        form.on('select(MaterialType)', function (data) {
            MaterialTypeChange(data.value);
            form.render();
        });
        function MaterialTypeChange(value) {
            if (value == "0") {
                $('#F_Customer').parent().parent().removeClass('layui-hide');
                $('#F_CustomerProNO').parent().parent().removeClass('layui-hide');
            }
            else {
                $('#F_Customer').parent().parent().addClass('layui-hide');
                $('#F_CustomerProNO').parent().parent().addClass('layui-hide');
                $('#F_Customer').val("");
                $('#F_CustomerProNO').val("");
            }
        }
        commonTable.rendertable({
            elem: '#currentTableId',
            data: [],
            defaultToolbar: [],
            search: false,
            limit: 9999,//每页数据 默认
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['count'] //自定义分页布局
                , first: false //不显示首页
                , last: false //不显示尾页
            },
            height: 'full-130',
            cols: [[
                { type: "checkbox", width: 50 },
                {
                    field: 'F_EqpUse', title: '设备用途', width: 110, sort: true, filter: true,
                    templet: function (d) {
                        return top.clients.dataItems["Mes_EqpUse"][d.F_EqpUse] == null ? "" : top.clients.dataItems["Mes_EqpUse"][d.F_EqpUse];
                    }
                },
                {
                    field: 'F_MouldType', title: '模具类型', width: 110, sort: true, filter: true,
                    templet: function (d) {
                        return top.clients.dataItems["Mes_MouldType"][d.F_MouldType] == null ? "" : top.clients.dataItems["Mes_MouldType"][d.F_MouldType];
                    }
                },
                { field: 'F_EqpName', title: '设备名称', width: 150, sort: true, filter: true },
                { field: 'F_Description', title: '设备描述', minWidth: 150, sort: true, filter: true },
            ]]
        });
        //加载数据
        wcLoading.close();
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            common.ajax({
                url: "/MaterialManage/MaterialEqp/GetGridJson",
                dataType: 'json',
                data: { itemId: keyValue, keyword: data.field.txt_keyword },
                async: false,
                success: function (data) {
                    if (data.data) {
                        table.reload('currentTableId', {
                            data: data.data
                        });
                    }
                }
            });
            return false;
        });
        //行点击事件监听，控制按钮显示
        var moreList = ["NF-delete"];//选择多条显示
        commonTable.tableRowClick("checkbox", "currentTableFilter", "currentTableId", null, moreList);
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            var data = table.checkStatus('currentTableId').data;
            if (obj.event === 'add') {  // 监听操作
                if (!keyValue) {
                    return false;
                }
                common.modalOpen({
                    title: "添加绑定",
                    url: "/MaterialManage/MaterialEqp/Form?itemId=" + keyValue,
                    width: "600px",
                    height: "600px",
                });
            }
            else if (obj.event === 'delete') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                var ids = [];
                for (var i = 0; i < data.length; i++) {
                    ids.push(data[i].F_Id);
                }
                common.deleteForm({
                    url: "/MaterialManage/MaterialEqp/DeleteForm",
                    param: { keyValue: ids.join(',') },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            return false;
        });
    });

</script>
<div class="layui-fluid" style="padding:0 0px">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md4 layui-col-xs5">
            <div class="layui-card" style="padding: 5px;">
                <fieldset class="table-search-fieldset" style="border:1px solid #e6e6e6">
                    <legend>物料</legend>
                    <div class="layui-form layuimini-form" lay-filter="adminform">
                        <div class="layui-form-item">
                            <label class="layui-form-label">物料分类</label>
                            <div class="layui-input-block">
                                <select id="F_MaterialType" name="F_MaterialType" lay-filter="MaterialType" lay-search>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">物料编号</label>
                            <div class="layui-input-block">
                                <input type="text" id="F_MaterialCode" name="F_MaterialCode" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">物料名称</label>
                            <div class="layui-input-block">
                                <input type="text" id="F_MaterialName" name="F_MaterialName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">物料描述</label>
                            <div class="layui-input-block">
                                <input type="text" id="F_MaterialDescription" name="F_MaterialDescription" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">物料单位</label>
                            <div class="layui-input-block">
                                <input type="text" id="F_MaterialUnit" name="F_MaterialUnit" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">物料规格</label>
                            <div class="layui-input-block">
                                <input type="text" id="F_MaterialSize" name="F_MaterialSize" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">客户名称</label>
                            <div class="layui-input-block">
                                <input type="text" id="F_Customer" name="F_Customer" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">客户品号</label>
                            <div class="layui-input-block">
                                <input type="text" id="F_CustomerProNO" name="F_CustomerProNO" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-block">
                                <textarea id="F_Description" name="F_Description" class="layui-textarea"></textarea>
                            </div>
                        </div>
                    </div>
                </fieldset>
            </div>
        </div>
        <div class="layui-col-md8 layui-col-xs7">
            <div class="layui-card" style="padding: 5px;">
                <fieldset class="table-search-fieldset" style="border:1px solid #e6e6e6">
                    <legend>绑定设备</legend>
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </fieldset>
                <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container" id="toolbar">
                        <button id="NF-add" authorize="yes" class="layui-btn layui-btn-sm data-add-btn" lay-event="add"><i class="layui-icon">&#xe654;</i>新建</button>
                        <button id="NF-delete" name="NF-delete" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                    </div>
                </script>
                <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
            </div>
        </div>
    </div>
</div>
